package electronic.registration.dao;

import electronic.registration.bo.Doctor;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Service;

import javax.print.Doc;
import java.util.List;

/**
 * User: Egor
 * Date: 10.11.11
 */
@Service
public class DoctorDaoImpl extends HibernateDaoSupport implements DoctorDao {

    @Autowired
    public void init(SessionFactory factory) {
        setSessionFactory(factory);
    }

    public void save(Doctor doctor) {
        getHibernateTemplate().save(doctor);
    }

    public List<Doctor> getAllDoctors() {
        return getHibernateTemplate().findByNamedQuery(Doctor.GET_ALL_DOCTORS);
    }

    public Doctor getDoctorByName(String name) {
        return (Doctor) getHibernateTemplate().findByNamedQuery(Doctor.GET_DOCTOR_BY_NAME, name).get(0);
    }
}
